//
//  TableViewController1.m
//  自定义单元格CustomCell
//
//  Created by student on 16/3/7.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "TableViewController1.h"

#import "TableViewCell.h"

@interface TableViewController1 ()

@property(nonatomic,strong)NSArray *list;

@end

@implementation TableViewController1

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.list = @[@{@"Name":@"MacPro",
                    @"Icon":@"macpro.jpg",
                    @"Color":@"White"},
                  @{@"Name":@"iMac",
                    @"Icon":@"imac.jpg",
                    @"Color":@"Black"},
                  @{@"Name":@"MacBook Air",
                    @"Icon":@"macbookair.jpg",
                    @"Color":@"Sliver"},
                  @{@"Name":@"Mac mini",
                    @"Icon":@"macmini.jpg",
                    @"Color":@"Sliver"},
                  @{@"Name":@"MacBookpro",
                    @"Icon":@"macbookpro.jpg",
                    @"Color":@"Sliver"}];
    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.list.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSDictionary *d = self.list[indexPath.row];
    
    // 方式1: 使用Tag找到原型单元格上的对象
//    
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
//    UIImageView *icon = [cell.contentView viewWithTag:101];
//    UILabel *nameLabel = [cell.contentView viewWithTag:102];
//    UILabel *colorLabel = [cell.contentView viewWithTag:103];
//    
//    icon.image = [UIImage imageNamed:d[@"Icon"]];
//    nameLabel.text = d[@"Name"];
//    colorLabel.text = d[@"Color"];

 //方式2：自定义UITableViewCell
    
    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    cell.iconImage.image=[UIImage imageNamed:d[@"Icon"]];
    cell.typeLabel.text=d[@"Name"];
    cell.colorLabel.text=d[@"Color"];
    
    
    
   
    
    return cell;
}



@end
